package com.example.g5project.repository.repo;

import com.example.g5project.entity.relation.ConsultInfo;
import com.example.g5project.repository.dao.ConsultInfoDao;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;

/**
 * @author Hu Zirui
 * @version 1.0.0
 * @ClassName AdministratorRepo.java
 * @Description TODO
 * @createTime 2022年03月23日 14:26:00
 */
@Component
@Transactional
public class ConsultInfoRepo extends Repo<ConsultInfo, Integer> {
    private final ConsultInfoDao consultInfoDao;

    protected ConsultInfoRepo(JpaRepository<ConsultInfo, Integer> dao, ConsultInfoDao consultInfoDao) {
        super(dao);
        this.consultInfoDao = consultInfoDao;
    }

    public void addConsultMessage(ConsultInfo consultInfo) {
        save(consultInfo);
    }

    public ArrayList<ConsultInfo> getAllConsultMessage() {
        return (ArrayList<ConsultInfo>) consultInfoDao.findAll(Sort.by(Sort.Direction.DESC, "id"));
    }

    public ConsultInfo getConsultMessage(String name, String date) {
        return consultInfoDao.findByNameAndDate(name, date);
    }

    public ArrayList<ConsultInfo> getAllConsultMessageByConsultName(String name) {
        return  consultInfoDao.getAllConsultMessageByConsultName(name);
    }


}
